package com.zq.it.pojo;

import com.zq.it.tool.BbsConstants;
import com.zq.it.tool.Prop;

public class Page {

    private int totalCount;
    private int currentPage;
    private int pageCount;
    private int offSet;
    private int pageSize = Integer.parseInt(Prop.get(BbsConstants.PAGE_SIZE));	
    private String url;

    public Page() {
        // empty
    }

    public Page(int currentPage) {
        this.currentPage = currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public boolean isFirstPage() {
        return currentPage <= 1 ? true : false;
    }

    public boolean isLastPage() {
        return currentPage >= pageCount ? true : false;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public int getOffSet() {
        offSet = (currentPage - 1) * pageSize;
        return offSet;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getCurrentPage() {
        if (currentPage < 1) {
            currentPage = 1;
        }
        if (currentPage > pageCount) {
            currentPage = pageCount;
        }
        return currentPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPageCount() {
        if (totalCount < 1) {
            pageCount = 0;
            return pageCount;
        }
        pageCount = (totalCount - 1) / pageSize + 1;
        return pageCount;
    }

    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }

    public void setOffSet(int offSet) {
        this.offSet = offSet;
    }
}
